
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1. 快速入门 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2ji-ben-zu-jian.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    序言
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="chapter1.html">
            
                <a href="chapter1.html">
            
                    
                    1. 快速入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="2ji-ben-zu-jian.html">
            
                <a href="2ji-ben-zu-jian.html">
            
                    
                    2.基本组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="2ji-ben-zu-jian/processor.html">
            
                <a href="2ji-ben-zu-jian/processor.html">
            
                    
                    2.1 Processor
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="2ji-ben-zu-jian/22-pipline.html">
            
                <a href="2ji-ben-zu-jian/22-pipline.html">
            
                    
                    2.2 Pipline
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="2ji-ben-zu-jian/23-sessionpool.html">
            
                <a href="2ji-ben-zu-jian/23-sessionpool.html">
            
                    
                    2.3 SessionPool
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="3pa-chong-kong-zhi.html">
            
                <a href="3pa-chong-kong-zhi.html">
            
                    
                    3.爬虫控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="4chou-qu-qi.html">
            
                <a href="4chou-qu-qi.html">
            
                    
                    4.抽取器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="4chou-qu-qi/41sipsoup.html">
            
                <a href="4chou-qu-qi/41sipsoup.html">
            
                    
                    4.1SipSoup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="4chou-qu-qi/42tableevaluator.html">
            
                <a href="4chou-qu-qi/42tableevaluator.html">
            
                    
                    4.2TableEvaluator
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="5zhong-zi-guan-li-qi.html">
            
                <a href="5zhong-zi-guan-li-qi.html">
            
                    
                    5.种子管理器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="6shi-jian-xun-huan.html">
            
                <a href="6shi-jian-xun-huan.html">
            
                    
                    6.事件循环
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                <a href="6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                    
                    6.1 eventLoop工作机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                <a href="6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                    
                    6.2 自动事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="6shi-jian-xun-huan/63delayevent.html">
            
                <a href="6shi-jian-xun-huan/63delayevent.html">
            
                    
                    6.3 延时事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="6shi-jian-xun-huan/64classScanner.html">
            
                <a href="6shi-jian-xun-huan/64classScanner.html">
            
                    
                    6.4 classScanner
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >1. 快速入门</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5FEB;&#x901F;&#x5165;&#x95E8;">&#x5FEB;&#x901F;&#x5165;&#x95E8;</h1>
<p>VSCrawler&#x7684;&#x4F7F;&#x7528;&#x5176;&#x5B9E;&#x4E0D;&#x96BE;&#xFF0C;&#x548C;&#x666E;&#x901A;&#x7684;&#x722C;&#x866B;&#x6846;&#x67B6;&#x7C7B;&#x4F3C;&#x3002;&#x5982;&#x4E0B;&#xFF1A;</p>
<h2 id="&#x4F9D;&#x8D56;&#x5F15;&#x5165;">&#x4F9D;&#x8D56;&#x5F15;&#x5165;</h2>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.virjar&lt;/groupId&gt;
    &lt;artifactId&gt;vscrawler-core&lt;/artifactId&gt;
    &lt;version&gt;0.0.1&lt;/version&gt;
&lt;/dependency&gt;
</code></pre><p>&#x8BF7;&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x6700;&#x65B0;&#x7248;</p>
<h2 id="&#x7B2C;1&#x4E2A;&#x722C;&#x866B;">&#x7B2C;1&#x4E2A;&#x722C;&#x866B;</h2>
<pre><code>public class CrawlerDemo {
    public static void main(String[] args) {

        // &#x542F;&#x52A8;&#x722C;&#x866B;
        VSCrawler vsCrawler = VSCrawlerBuilder.create()// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x5668;
                .build();
        //vsCrawler &#x5F3A;&#x5236;&#x5B9E;&#x73B0;&#x4E86;&#x65AD;&#x70B9;&#x7EED;&#x722C;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x662F;&#x505A;&#x6D4B;&#x8BD5;&#xFF0C;&#x5EFA;&#x8BAE;&#x5728;&#x5F00;&#x542F;&#x722C;&#x866B;&#x524D;&#x6E05;&#x7A7A;&#x5386;&#x53F2;&#x4EFB;&#x52A1;&#xFF0C;&#x5426;&#x5219;&#x4F60;&#x7684;&#x79CD;&#x5B50;&#x53EF;&#x80FD;&#x4E0D;&#x80FD;&#x6210;&#x529F;&#x52A0;&#x5165;&#x4EFB;&#x52A1;&#x961F;&#x5217;
        vsCrawler.clearTask();

        //&#x5F00;&#x59CB;&#x722C;&#x866B;
        vsCrawler.start();

        // &#x589E;&#x52A0;&#x79CD;&#x5B50;
        System.out.println(&quot;&#x6CE8;&#x5165;&#x4E00;&#x4E2A;&#x79CD;&#x5B50;&#x4EFB;&#x52A1;&quot;);
        vsCrawler.pushSeed(&quot;http://www.java1234.com/&quot;);
    }
}
</code></pre><p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5C31;&#x4F1A;&#x4ECE;<a href="http://www.java1234.com/" target="_blank">http://www.java1234.com/</a> &#x5F00;&#x59CB;&#x904D;&#x5386;&#x6240;&#x6709;&#x7F51;&#x9875;&#x94FE;&#x63A5;,&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x6211;&#x4EEC;&#x5E76;&#x6CA1;&#x6709;&#x5BF9;&#x6293;&#x53D6;&#x505A;&#x4EFB;&#x4F55;&#x5B9A;&#x5236;&#xFF0C;&#x6BD4;&#x5982;&#x5982;&#x4F55;&#x63A7;&#x5236;&#x722C;&#x866B;&#x8FB9;&#x754C;&#xFF0C;&#x5982;&#x4F55;&#x5904;&#x7406;&#x6587;&#x672C;&#x5185;&#x5BB9;&#xFF0C;&#x5982;&#x4F55;&#x5904;&#x7406;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x7B49;&#x7B49;&#x3002;&#x6240;&#x4EE5;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x4E00;&#x4E9B;&#x6293;&#x53D6;&#x53C2;&#x6570;&#x3002;</p>
<pre><code>public class CrawlerDemo {
    public static void main(String[] args) {

        // &#x542F;&#x52A8;&#x722C;&#x866B;
        VSCrawler vsCrawler = VSCrawlerBuilder.create()// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6784;&#x9020;&#x5668;
                .setProcessor(new PageDownLoadProcessor() {
                    @Override
                    protected void parse(Seed seed, String result, CrawlResult crawlResult) {
                        if (StringUtils.isEmpty(result)) {
                            return;
                        }
                        List&lt;String&gt; strings = allUrl(Jsoup.parse(result, seed.getData()));
                        crawlResult.addResults(strings);
                        // &#x63A7;&#x5236;&#x722C;&#x866B;&#x8FB9;&#x7F18;&#x5728;www.java1234.com &#x7AD9;&#x5185;&#x6267;&#x884C;
                        crawlResult.addStrSeeds(Lists.newLinkedList(Iterables.filter(strings, new Predicate&lt;String&gt;() {
                            @Override
                            public boolean apply(String input) {
                                return StringUtils.startsWithIgnoreCase(input, &quot;http://www.java1234.com&quot;);
                            }
                        })));
                    }
                }).setSessionPoolCoreSize(15)// &#x6838;&#x5FC3;15&#x4E2A;&#x7528;&#x6237;
                .setSessionPoolMaxSize(55)// &#x6700;&#x591A;55&#x4E2A;&#x7528;&#x6237;
                .setSessionPoolReuseDuration(60 * 1000)// &#x6BCF;&#x4E2A;&#x7528;&#x6237;1&#x5206;&#x949F;&#x4E4B;&#x5185;&#x4E0D;&#x80FD;&#x540C;&#x65F6;&#x4F7F;&#x7528;
                .setSessionPoolMaxOnlineDuration(10 * 60 * 1000)// &#x6BCF;&#x4E2A;&#x7528;&#x6237;&#x6700;&#x591A;&#x5B58;&#x6D3B;10&#x5206;&#x949F;
                .setWorkerThreadNumber(10)// &#x722C;&#x866B;&#x7EBF;&#x7A0B;&#x6570;&#x76EE;&#x4E3A; 10&#x4E2A;
                .build();
        vsCrawler.clearTask();

        vsCrawler.start();

        // &#x589E;&#x52A0;&#x79CD;&#x5B50;
        System.out.println(&quot;&#x6CE8;&#x5165;&#x4E00;&#x4E2A;&#x79CD;&#x5B50;&#x4EFB;&#x52A1;&quot;);
        vsCrawler.pushSeed(&quot;http://www.java1234.com/&quot;);
    }
}
</code></pre><p>&#x5982;&#x4E0A;&#x7528;&#x6CD5;&#xFF0C;&#x4F60;&#x4F1A;&#x53D1;&#x73B0;&#x548C;&#x56FD;&#x5185;&#x7C7B;&#x4F3C;&#x7684;&#x722C;&#x866B;&#x6846;&#x67B6;&#x5F88;&#x7C7B;&#x4F3C;&#xFF0C;&#x7684;&#x786E;&#x4E3A;&#x4E86;&#x4F7F;&#x7528;&#x6237;&#x4F7F;&#x7528;&#x7B80;&#x5355;&#xFF0C;VSCrawler&#x5728;&#x8BBE;&#x8BA1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C31;&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x4FDD;&#x6301;&#x548C;&#x5176;&#x4ED6;&#x6846;&#x67B6;&#x7528;&#x6CD5;&#x7C7B;&#x4F3C;&#x3002;&#x722C;&#x866B;&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x5927;&#x5BB6;&#x90FD;&#x5DEE;&#x4E0D;&#x591A;&#xFF0C;&#x5C31;&#x4E0D;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E86;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 序言">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2ji-ben-zu-jian.html" class="navigation navigation-next " aria-label="Next page: 2.基本组件">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1. 快速入门","level":"1.2","depth":1,"next":{"title":"2.基本组件","level":"1.3","depth":1,"path":"2ji-ben-zu-jian.md","ref":"2ji-ben-zu-jian.md","articles":[{"title":"2.1 Processor","level":"1.3.1","depth":2,"path":"2ji-ben-zu-jian/processor.md","ref":"2ji-ben-zu-jian/processor.md","articles":[]},{"title":"2.2 Pipline","level":"1.3.2","depth":2,"path":"2ji-ben-zu-jian/22-pipline.md","ref":"2ji-ben-zu-jian/22-pipline.md","articles":[]},{"title":"2.3 SessionPool","level":"1.3.3","depth":2,"path":"2ji-ben-zu-jian/23-sessionpool.md","ref":"2ji-ben-zu-jian/23-sessionpool.md","articles":[]}]},"previous":{"title":"序言","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter1.md","mtime":"2017-06-24T05:15:46.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-06-25T14:04:12.299Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

